﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace BlogApi.Migrations
{
    public partial class InitCreate : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Users_table",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    Email = table.Column<string>(type: "varchar", nullable: false),
                    Password = table.Column<string>(type: "varchar", nullable: false),
                    NickName = table.Column<string>(nullable: true),
                    UserImageUrl = table.Column<string>(nullable: true),
                    Introduction = table.Column<string>(nullable: true),
                    FanNumber = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Users_table", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Articles_table",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    Title = table.Column<string>(nullable: false),
                    Content = table.Column<string>(type: "ntext", nullable: false),
                    UserId = table.Column<Guid>(nullable: false),
                    GoodNumber = table.Column<int>(nullable: false),
                    CommentNumber = table.Column<int>(nullable: false),
                    BrowseNumber = table.Column<int>(nullable: false),
                    Status = table.Column<string>(nullable: true),
                    PublishedDate = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Articles_table", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Articles_table_Users_table_UserId",
                        column: x => x.UserId,
                        principalTable: "Users_table",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArticleTags_table",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    TagName = table.Column<string>(nullable: true),
                    UserId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArticleTags_table", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ArticleTags_table_Users_table_UserId",
                        column: x => x.UserId,
                        principalTable: "Users_table",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Fans_table",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    AuthorId = table.Column<Guid>(nullable: false),
                    UserId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Fans_table", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Fans_table_Users_table_AuthorId",
                        column: x => x.AuthorId,
                        principalTable: "Users_table",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Fans_table_Users_table_UserId",
                        column: x => x.UserId,
                        principalTable: "Users_table",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Comments_table",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    UserId = table.Column<Guid>(nullable: false),
                    ArticleId = table.Column<Guid>(nullable: false),
                    Content = table.Column<string>(type: "ntext", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Comments_table", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Comments_table_Articles_table_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "Articles_table",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Comments_table_Users_table_UserId",
                        column: x => x.UserId,
                        principalTable: "Users_table",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Likes_table",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    ArticleId = table.Column<Guid>(nullable: false),
                    UserId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Likes_table", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Likes_table_Articles_table_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "Articles_table",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Likes_table_Users_table_UserId",
                        column: x => x.UserId,
                        principalTable: "Users_table",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArticleToArticleTags_table",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    ArticleId = table.Column<Guid>(nullable: false),
                    ArticleTagId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArticleToArticleTags_table", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ArticleToArticleTags_table_Articles_table_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "Articles_table",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArticleToArticleTags_table_ArticleTags_table_ArticleTagId",
                        column: x => x.ArticleTagId,
                        principalTable: "ArticleTags_table",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Articles_table_UserId",
                table: "Articles_table",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleTags_table_UserId",
                table: "ArticleTags_table",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleToArticleTags_table_ArticleId",
                table: "ArticleToArticleTags_table",
                column: "ArticleId");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleToArticleTags_table_ArticleTagId",
                table: "ArticleToArticleTags_table",
                column: "ArticleTagId");

            migrationBuilder.CreateIndex(
                name: "IX_Comments_table_ArticleId",
                table: "Comments_table",
                column: "ArticleId");

            migrationBuilder.CreateIndex(
                name: "IX_Comments_table_UserId",
                table: "Comments_table",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_Fans_table_AuthorId",
                table: "Fans_table",
                column: "AuthorId");

            migrationBuilder.CreateIndex(
                name: "IX_Fans_table_UserId",
                table: "Fans_table",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_Likes_table_ArticleId",
                table: "Likes_table",
                column: "ArticleId");

            migrationBuilder.CreateIndex(
                name: "IX_Likes_table_UserId",
                table: "Likes_table",
                column: "UserId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ArticleToArticleTags_table");

            migrationBuilder.DropTable(
                name: "Comments_table");

            migrationBuilder.DropTable(
                name: "Fans_table");

            migrationBuilder.DropTable(
                name: "Likes_table");

            migrationBuilder.DropTable(
                name: "ArticleTags_table");

            migrationBuilder.DropTable(
                name: "Articles_table");

            migrationBuilder.DropTable(
                name: "Users_table");
        }
    }
}
